package question2;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

/**
 * @FileName Client
 * @Description
 * @Author Sword
 * @date 2024-12-24
 **/
public class Client {
    public static void main(String[] args) throws IOException {
        String hostname = "localhost";
        int port = 12345;
        try (Socket socket = new Socket(hostname, port);
             PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
             BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()))) {

            out.println("Hello from client");
            String response = in.readLine();
            System.out.println("服务器响应: " + response);
        }
    }
}
